document.addEventListener('DOMContentLoaded', function() {
    const likebtn = document.getElementById('like-btn')
    const imageid = document.getElementById('image-card').dataset.id
    likebtn.addEventListener('click', function() {
        fetch('/likes', {
                method: 'post',
                headers: new Headers({
                    'Content-Type': 'application/x-www-form-urlencoded'
                }),
                body: 'imageid=' + imageid
            })
            .then(resp => resp.json())
            .then(newimage => {
                document.getElementById('span-likes').textContent = newimage.likes
            })
    })
})